<template>
  <div class="block" v-loading="loading">
    <el-upload
      class="upload-demo"
      :action="host+'upload'"
      :headers="token"
      :on-progress="handlep"
      multiple
      :on-error="handleError"
      :limit="3"
      :file-list="filename"
      :on-success="handleSuccess"
      ref="upload"
    >
      <el-button size="small">点击上传</el-button>
    </el-upload>
          <el-button class="buttonx" size="small" style="float:right" @click="$router.back(-1)">返回</el-button>
    <div class="date">
      <el-date-picker
        value-format="yyyy-MM-dd HH:mm:ss"
        format="yyyy-MM-dd HH:mm:ss"
        v-model="date"
        type="date"
        placeholder="选择日期"
      ></el-date-picker>
      <el-button @click="submit" class="button">提交</el-button>
    </div>
  </div>
</template>
<script>
import { getToken } from "@/utils/auth";
import request from "@/utils/request";
export default {
  data() {
    return {
      loading: false,
      doc: "",
      itemid: "",
      date: "",
      filename: [{ name: "" }],
      token: { token: getToken() },
      p: {
        file: 1
      },
      value1: ""
    };
  },
  created() {
    this.host = this.$host;
    this.itemid = this.$route.query.id;
  },
  methods: {
    handleSuccess(response, file, fileList) {
      var that = this;
      console.log(response.object);
      if (response.code == 1) {
        this.$message.success("上传成功！");
        that.doc = response.object;
      } else {
        that.$message.error(response.message);
      }
    },
    submit() {
      this.loading = true;
      var that = this;
      console.log(this);
      var resdata = { date: that.date, doc: that.doc, itemId: that.itemid };
      console.log(resdata);
      request(`/opinion/zerosumit`, {
        method: "get",
        headers: {
          "Content-Type": "application/json"
        },
        params: resdata
      })
        .then(res => {
          that.loading = false;
          console.log(res);
          if (res.data.code == 1) {
            that.$message.success(res.data.message);
            setTimeout(() => {
              that.$router.go(-1); //返回上一层
            }, 500);
          } else {
            that.$message.error(res.data.message);
          }
        })
        .catch(e => {
          that.loading = false;
          console.log(e);
        });
    },
    // download(e) {
    //   request(`download`, {
    //     method: "get",
    //     headers: {
    //       "Content-Type": "application/json",
    //       token: getToken(),
    //       type: 1
    //     },
    //     params: { fileurl: e }
    //   })
    //     .then(res => {
    //       console.log(res);
    //       this.$message.success("下载成功");
    //       console.log(res);
    //     })
    //     .catch(e => {
    //       console.log(e);
    //     });
    // },
    handlep(event, file, fileList) {
      this.filename.map((v, i) => {
        v.file = file.name;
      });
      console.log(this.filename);
    },
    handleError(err, file, fileList) {
      console.log(err);
      this.$message.error("上传失败！");
    }
  }
};
</script>

<style scoped>
.uploader-drop {
  border: 1px solid#ccc !important;
}
.button {
  margin-top: 50px;
  display: block;
}
.date {
  margin-top: 45px;
}
.block {
  position:relative;
  width: 565px;
  margin: 50px 80px;
  padding: 46px;
  box-shadow: 0 0 10px #dacece;
}
.uploader-example {
  width: 880px;
  padding: 15px;
  margin: 40px auto 0;
  font-size: 12px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.4);
}
.uploader-example .uploader-btn {
  margin-right: 4px;
}
.uploader-example .uploader-list {
  max-height: 440px;
  overflow: auto;
  overflow-x: hidden;
  overflow-y: auto;
}
</style>